/**
 * @file models/accountDailies.js
 * @author
 */

import { routerRedux } from 'dva/router';
import api from '../api';
import { delay } from '../utils/sagaEffects';

export default {
  namespace: 'retailAccountAssets',
  state: {
    openPositionList: [],
    accountDaily: undefined,
    specialTradings: [],
    educationDocs: undefined,
		commentConfig: {},
		featureRanks: [],
  },
  reducers: {
    getAccountDailySuccess(state, action) {
      const { payload: { response } } = action;
      return {
        ...state,
        accountDaily: response.data,
      };
    },
    getOpenPositionListSuccess(state, action) {
      const { payload: { response } } = action;
      return {
        ...state,
        openPositionList: response,
      };
    },
    getSpecialTradingsSuccess(state, action) {
      const { payload: { response } } = action;
      return {
        ...state,
        specialTradings: response,
      };
    },
		getCommentConfigSuccess(state, action) {
			const { payload: { response } } = action;
			return {
				...state,
				commentConfig: response,
			};
		},
		getFeatureRanksSuccess(state, action) {
			const { payload: { response } } = action;
			return {
				...state,
				featureRanks: response,
			};
		},
    getEducationDocsSuccess(state, action) {
      const { payload: { response } } = action;
      return {
        ...state,
        educationDocs: response.data.document.members,
        educationKeywords: response.data.keywords.members,
      };
    },
  },
  effects: {
    * getAccountDaily({ payload: query }, { call, put }) {
      const response = yield call(api.getRetailAccountDailies, query);
      yield put({
        type: 'getAccountDailySuccess',
        payload: { response },
      });
    },
    * getOpenPositionList({ payload: query }, { call, put }) {
      const response = yield call(api.getRetailOpenPositions, query);
      yield put({
        type: 'getOpenPositionListSuccess',
        payload: { response },
      });
    },
    * getSpecialTradings({ payload: query }, { call, put }) {
      const response = yield call(api.getRetailSpecialTradings, query);
      yield put({
        type: 'getSpecialTradingsSuccess',
        payload: { response },
      });
    },
		* getCommentConfig({ payload: query }, { call, put }) {
			const response = yield call(api.getRetailCommentConfig, query);
			yield put({
				type: 'getCommentConfigSuccess',
				payload: { response },
			});
		},
		* getFeatureRanks({ payload: query }, { call, put }) {
			const response = yield call(api.getRetailFeatureRanks, query);
			yield put({
				type: 'getFeatureRanksSuccess',
				payload: { response },
			});
		},
    * getEducationDocs({ payload: query }, { call, put }) {
      const response = yield call(api.getRetailEducationDocs, query);
      yield put({
        type: 'getEducationDocsSuccess',
        payload: { response },
      });
    },
  },
  subscriptions: {},
};
